<template>
	<!-- 添加弹框 -->
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;"></i>
		<div class="bt">课程添加</div>
		<div class="input-block">
			<span>课程名称</span>
			<el-input v-model="vzsmc" placeholder="请输入课程名称" icon="add" class="input"></el-input>
		</div>
		<div class="input-block" style="margin-top: 20px;">
			<span>课程教材</span>
			<!--<el-input v-model="vmc" placeholder="请输入课程教材" icon="add" class="input"></el-input>-->
			<el-select v-model="vmc" placeholder="请选择课程教材" class="input">
							<el-option :label="v.mc" :value="v.mc" v-for="v in comboxlist"></el-option>
						</el-select>
			<!--<el-button size="small" @click="showwp()" class="select-block2" >选择</el-button>-->
		</div>
		<div class="input-block">
			<span>课时数量</span>
			<el-input v-model="vks" type="number" placeholder="请输入课时数量" icon="add" class="input"></el-input>
		</div>
		<div class="input-block">
			<span>课程时长</span>
			<el-input v-model="vsc" type="number" placeholder="请输入课程时长  (分钟)" icon="add" class="input"></el-input>
        </div>
        <div class="input-block">
			<span>课程总价</span>
			<el-input v-model="vjg" type="number" placeholder="请输入课程单价 (元)" icon="add" class="input" ></el-input>
		</div>
		<div class="input-block">
			<span>课程单价</span>
			<el-input v-model="jcjg" type="number"  disabled placeholder="请输入课程单价 (元)" icon="add" class="input"></el-input>
		</div> 
		<div class="input-block">
			<span>满班人数</span>
			<el-input v-model="vmbcns" type="number" placeholder="请输入满班人数" icon="add" class="input"></el-input>
		</div>
		<div class="input-block">
			<span>是否启用</span>
			<el-select v-model="visqy" class="input">
				<el-option label="启用" value="Y"></el-option>
				<el-option label="禁用" value="N"></el-option>
			</el-select>
		</div>
		<div class="input-block">
			<span>备注</span>
			<el-input v-model="vnote" type="textarea" :rows="2" placeholder="请输入备注内容" icon="add" class="input"></el-input>
		</div>
		<Kschoose class="wpfl" @wpchoose="wpchooseed" @close="wpchoosecancel" v-if="showchoselist"></Kschoose>
		<div class="an">
			<el-button type="primary" class="submit" @click="submit">保存</el-button>
			<el-button type="danger" class="submit" @click="cancel">退出</el-button>
		</div>
	</el-dialog>
</template>
<script type="text/javascript">
	import Kschoose from '../../manage/kssz/kschoose'
	import qs from 'qs'
	export default {
		components: {
			Kschoose
		},
		data() {
			return {
				showchoselist: false,
				vfxkcidmc: '',
				vjg: '',
//				vjcjg: '',
				vks: '',
				vsc:'',
				vzsmc:'',
				vmbcns:'',
				vmc: '',
				visqy: 'Y',
				vnote: '',
				comboxlist:[],
				dialogTableVisible: true
			}
		},
		created() {
			this.getcomboxlist();
		},
		methods: {
			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					xxid: logininfo.xxid,
					yhid: logininfo.id
				})
				//执行
				this.axios.post(this.$store.state.api + 'wpfl/getjc', params2)
					.then(res => {
//						console.log(res,'sssssssssss')
						let data = res.data.data.list;
						let list = data;
						this.comboxlist = list;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			submit() {
				//检测
				this.$store.state.loading = true;
				if(!this.vmc) {
					this.$message.warning('请选择课程教材');
					this.$store.state.loading = false;
					return;
				} else if(!this.vzsmc) {
					this.$message.warning('请填写课程名称');
					this.$store.state.loading = false;
					return;
				} else if(!this.vks) {
					this.$message.warning('请填写课时数量');
					this.$store.state.loading = false;
					return;
				} else if(!this.vsc) {
					this.$message.warning('请填写课程时间');
					this.$store.state.loading = false;
					return;
				} else if(!this.vjg) {
					this.$message.warning('请填写课程总价');
					this.$store.state.loading = false;
					return;
				} else if(!this.vmbcns) {
					this.$message.warning('请填写满班人数');
					this.$store.state.loading = false;
					return;
				}
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					jcjg: this.jcjg,
					zsmc:this.vzsmc,
					ks: this.vks,
					mc: this.vmc,
					sc: this.vsc,
					jg: this.vjg,
					mbcns: this.vmbcns,
					isqy: this.visqy,
					note: this.vnote,
					yhid: logininfo.id,
					xxid: logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'kcfl/insert', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', {type: 'add',cancel: false});
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
							this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.danger("服务器异常!")
						this.$store.state.loading = false;
					})
			},
			showwp() {
				this.showchoselist = true;
			},
			wpchooseed(josndata) {
//				console.log(josndata, 'wzwZ');
				//				this.vfxkcidmc = josndata.kcmc;
				this.vfxkcid = josndata.fxkcid;
				this.vkssl = josndata.kssl;
				this.showchoselist = false;
			},
			wpchoosecancel(setting) {
				if(setting.cancel == false) {
					this.vfxkcid = setting.data[0].id;
					//					this.vfxkcidmc = setting.data[0].mc;
					this.vjcidmc = setting.data[0].cmc;
					this.vjcid = setting.data[0].jcid;
					this.vcid = setting.data[0].cid;
					this.vkssl = setting.data[0].number;
				}
				this.showchoselist = false;
			},
			cancel() {
				this.$emit('close', {type: 'add',cancel: true})
				}
		},
		computed: {
			jcjg() {
				let number = this.vjg / this.vks;
				if(number <= 0) {
					return 0.00
				}
				return number;
			},
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.bt {
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top: 0;
			left: 0;
			// margin-top: -70px;
			background: #50BFFF;
			// margin-left: -20px;
			// margin-bottom: 20px;
			color: white;
			text-align: left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
		.close {
			z-index: 10;
			position: absolute;
			font-size: 20px;
		}
		.input {
			vertical-align: middle;
			width: 80%;
			display: inline-block;
		}
		.input-block span {
			display: inline-block;
			width: 90px;
			text-align: right;
		}
		.submit {
			width: 120px;
			margin: 0 auto;
		}
		.an {
			width: 100%;
			margin: 0 auto;
			text-align: center;
		}
	}
</style>